import { useStorage } from "@vueuse/core";
import Cookies from "js-cookie";

const cookiePrefix = `${import.meta.env.VITE_COOKIE_PREFIX}_cookie_`
const tokenKey = `${import.meta.env.VITE_STORAGE_PREFIX}_token`;
const tokenStorage = useStorage(tokenKey, null);

export const getToken = () => tokenStorage.value;

export const setToken = (access_token) => (tokenStorage.value = access_token);

export const removeToken = () => (tokenStorage.value = null);

export function getCookie(key) {
  return Cookies.get(`${cookiePrefix}${key}`);
}

export function setCookie(key, value) {
  Cookies.set(`${cookiePrefix}${key}`, value, { expires: 30 });
}

export function removeCookie(key) {
  return Cookies.remove(`${cookiePrefix}${key}`);
}
